package com.adxon.servlet;

import com.adxon.MsgException;
import com.adxon.cookie.Station;
import com.adxon.data.Item;
import com.adxon.data.User;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.*;

@SuppressWarnings("serial")
public class PasswordServlet extends ServletBase{
	public void doGet(HttpServletRequest req,HttpServletResponse resp)
			throws IOException,ServletException{
		Item c=Station.getCurrentUser(req);
		if(c==null)
			forward403(req,resp);
		User u=new User();
		try{
			u.setAll(req);
			if(req.getParameter("ok")!=null){
				u.update(c.getId());
				u.checkPassword();
				u.checkNewPass();
				u.setTime(0);
				u.commit();
				System.out.println(u.getPassword());
			}
		}catch(MsgException e){
			e.getMessage(req);
		}
		setAttributes(req,null);
		u.getAll(req);
		forward("password.jsp",req,resp);
	}
	public void doPost(HttpServletRequest req,HttpServletResponse resp)
			throws IOException,ServletException{
		doGet(req,resp);
	}
}